from table_list import *
from create_import import *


def create_description(table: str):
    local_path = __file__  # 当前文件路径
    local_dir = os.path.dirname(local_path)  # 当前文件夹
    description_dir = f"{local_dir}/description"
    if not os.path.exists(description_dir):
        os.makedirs(description_dir)
    _url_output = output(f"{description_dir}/{table}.des")

    def printf(val):
        print(val, file=_url_output)

    with open(f"{local_dir}/{table}.txt", "r", encoding="utf-8") as f:
        lines = f.readlines()
        names = []
        for line in lines:
            names.append(line.rstrip().lower().split(","))

        cols = lines[1].rstrip().split(",")
        comments = lines[0].rstrip().split(",")
        types = lines[2].rstrip().split(",")

        mxcol = mxcomment = maxtpye = 0
        for k in range(len(cols)):
            col = cols[k].lower()
            comment = comments[k]
            word = col.strip()
            tpye = types[k]
            mxcol = max(mxcol, len(col))
            mxcomment = max(mxcomment, len(comment))
            maxtpye = max(maxtpye, len(tpye))
        for k in range(len(cols)):
            col = cols[k].lower()
            comment = comments[k]
            word = col.strip()
            tpye = types[k]
            printf(
                f"{uppercase_except_first(word).ljust(mxcol)} {comment.ljust(mxcomment)}"
            )


if __name__ == "__main__":
    for table in table_list:
        create_description(table=table)
